#ifndef TABLEMODEL_H
#define TABLEMODEL_H

#include <QSqlTableModel>
#include <QSqlDatabase>

class TableModel : public QSqlTableModel
{
    Q_OBJECT

public:
    explicit TableModel(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
    
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    
    void setTable(const QString &tableName);
    bool submitAllWithValidation();
    
private:
    bool validateData(const QModelIndex &index, const QVariant &value) const;
};

#endif // TABLEMODEL_H